﻿#pragma once
#ifndef _POLLER_H_
#define _POLLER_H_
#include "base_type.h"
#include <memory>
#include <vector>
#include <map>
#include "as_socket.h"

struct epoll_event;
namespace as {
namespace net {
class Channel;
class EpollWatch;
class Poller
{
public:
	typedef std::map<socket_fd, Channel*> ChannelMap;
	Poller(EpollWatch *ep_watch);
	void Add(socket_fd fd, uint32_t events);
	void Modify(socket_fd fd, uint32_t events);
	void Remove(socket_fd fd);

	void AddChannel(Channel *channel);
	void ModifyChannel(Channel *channel);
	void RemoveChannel(Channel *channel);


	void UpdateChannel(Channel *channel);
	int Wait(epoll_event* events, int max_events, int timeout);
	

	void pool(std::vector<Channel*> &channelVec);

private:
	EpollWatch *ep_watch_ = nullptr;
	ChannelMap channel_map_;
};


}
}
#endif